// packagBuy/pages/commonProblem/index/index.js
var util = require('../../../../utils/util')   //引入配置公共请求接口
import { foundApi } from '../../../../config/config'
//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    footprintGuid: '', //足迹全局id
    urlData: '/packagBuy/pages/commonProblem/secondaryPage/secondaryPage?title=' + '购物指南',
    listData: [],
    page: 0,
    rows: 3,
    nomoreData: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getHelpPag()
  },
  getHelpPag() {
    let that = this
    let params = {
      "page": that.data.page,
      "rows": that.data.rows
    }
    app.reqFun.requestJson('POST',foundApi.helpPag,params,(res)=>{
      if(res.data.success === 1) {
        let records = res.data.data.records
         for(var i = 0, len = records.length; i < len; i++) {
          if (records[i].childList) {
            for(var j = 0, lens = records[i].childList.length; j < lens; j++) {
              let option = {
                id: records[i].childList[j].id,
                name: records[i].childList[j].name
              }
              records[i].childList[j].urlData = '/packagBuy/pages/commonProblem/secondaryPage/secondaryPage?option=' + JSON.stringify(option)
            }
          }
        }
        // this.setData({
        //   src: webUrl
        // })
        if (records.length < that.data.rows || records.length == that.data.rows) {
          that.setData({
            nomoreData: true
          })
        }
        that.setData({
          listData: that.data.listData.concat(records)
        })
        console.log('listData', that.data.listData)
      }
    })
  },
  goSearchProblem() {
    wx.navigateTo({
      url: '../questionSearch/questionSearch',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      footprintGuid: util.guid()
    })
    //保存访问足迹
    app.saveAccessFootprint(this.data.footprintGuid, 'help', 0)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    //保存退出足迹
    app.saveQuitFootprint(this.data.footprintGuid)
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    //保存退出足迹
    app.saveQuitFootprint(this.data.footprintGuid)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.nomoreData) {
      this.setData({
        page: this.data.page + 1
      })
      this.getHelpPag()
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})